import { login } from '@/api/user'
const store = {
  namespaced: true,
  state: {
    token: '',
    username: '',
    id: ''
  },
  getters: {

  },
  mutations: {
    setStateInfo (state, data) {
      state.token = data.token
      state.username = data.userName
      state.id = data.userId
    },
    delInfo (state) {
      state.token = ''
      state.username = ''
      state.id = ''
    }
  },
  actions: {
    async loginAction (context, payload) {
      const data = await login(payload)
      if (data.token) {
        context.commit('setStateInfo', data)
      } else {
        return Promise.reject(data.msg)
      }
    }
  }
}

export default store
